/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.fca.daos;

import db.dao.AbstractDAO;
import db.orm.BeansGenerator;
import edu.fca.beans.AcreditacionBean;
import java.util.ArrayList;

/**
 *
 * @author Romms
 */
public class AcreditacionDAO extends AbstractDAO<AcreditacionBean> {

    @Override
    public void add(AcreditacionBean entity) throws Exception {
        super.setQuery("INSERT INTO acreditacion (" +
            "calificacion," +
            "status," +
            "alumnoMatricula,"+
            "calendarioCodigo) " +
            "VALUES" + "("+ entity.getCalificacion()+ ",'" +
            entity.getStatus()+ "','" +
            entity.getAlumnoMatricula()+ "','" +
            entity.getCalendarioCodigo()+ "')");
        super.connectionManager.getConnection().executeUpdate(super.getQuery());
        this.connectionManager.closeDbConnection(super.connectionManager.getConnection());
    }

    @Override
    public void deleteWhere(String condition) throws Exception {
        super.setQuery("DELETE FROM acreditacion WHERE " + condition);
        super.connectionManager.getConnection().executeUpdate(super.getQuery());
        this.connectionManager.closeDbConnection(super.connectionManager.getConnection());
    }

    @Override
    public void updateWhere(AcreditacionBean entity, String condition) throws Exception {
        super.setQuery("UPDATE acreditacion SET " +
            "calificacion="+entity.getCalificacion()+
             ",status='"+ entity.getStatus()+
             "',alumnoMatricula='"+ entity.getAlumnoMatricula()+
             "',calendarioCodigo='"+ entity.getCalendarioCodigo()+
             "' WHERE "+ condition);
        super.connectionManager.getConnection().executeUpdate(super.getQuery());
        this.connectionManager.closeDbConnection(super.connectionManager.getConnection());
    }

    @Override
    protected ArrayList<AcreditacionBean> select() throws Exception {
        ArrayList<AcreditacionBean> list  =BeansGenerator.getInstance().generateListOfBeans
                (super.connectionManager.getConnection().executeQuery(this.getQuery()), AcreditacionBean.class);
        this.connectionManager.closeDbConnection(super.connectionManager.getConnection());
        return list;
    }

    @Override
    public ArrayList<AcreditacionBean> selectAll() throws Exception {
        this.setQuery("SELECT * FROM acreditacion");
        return this.select();
    }

    @Override
    public ArrayList<AcreditacionBean> selectWhere(String condition) throws Exception {
        this.setQuery("SELECT * FROM acreditacion WHERE "+condition);
        return this.select();
    }

}
